<!-- 
 * @Author: guanpf 992093924@qq.om
 * @Date: 2023-09-16 19:17:24
 * @LastEditTime: 2023-09-25 20:24:05
 * @LastEditors: guanpf
 * @Description: 
 * @FilePath: /ZCGL_WX/src/views/main/asset/components/active-num.vue
 -->
<template>
  <!-- 活跃数 -->
  <div class="active-num statistic-item">
    <div class="top">
      <div class="title">
        <div class="common-title">活跃数</div>
        <div class="tip">资产登记、转移、借出等操作总数</div>
      </div>
      <div class="year">2023年</div>
    </div>
    <div class="histogram">
      <div class="arrow-back-btn" @click="reduceFun" v-show="dataList.length>6">
        <x-icon class="arrow-back-cion" type="ios-arrow-back" size="16"></x-icon>
      </div>
      <div class="histogram-content">
        <div class="histogram-list">
          <template v-if="histogramIndex == 0">
            <div
              class="histogram-item"
              v-for="(item, index) in dataList.slice(0, 6)"
              :key="index"
            >
              <div>{{ item.subtotal }}</div>
              <div class="column" :style="`height:calc(${(item.subtotal / maxSubtotal) * 100}% - 46px)`"></div>
              <div>{{ item.mon }}</div>
            </div>
          </template>
          <template v-if="histogramIndex == 1 && dataList.length>6">
            <div
              class="histogram-item"
              v-for="(item, index) in dataList.slice(6, 12)"
              :key="index"
            >
              <div>{{ item.subtotal }}</div>
              <div class="column" :style="`height:calc(${(item.subtotal / maxSubtotal) * 100}% - 46px)`"></div>
              <div>{{ item.mon }}</div>
            </div>
          </template>
        </div>
      </div>
      <div class="arrow-back-btn" @click="increaseFun" v-show="dataList.length>6">
        <x-icon class="arrow-back-cion" type="ios-arrow-forward" size="16"></x-icon>
      </div>
    </div>
  </div>
</template>

<script>
import AssetApi from "@/api/asset.js";
export default {
  data() {
    return {
      dataList: [],
      histogramIndex: 0,
      maxSubtotal:null
    };
  },
  mounted() {
    this.getYearActive()
  },
  methods: {
    reduceFun(){
        if(this.histogramIndex==1){
            this.histogramIndex -- 
        }
    },
    increaseFun(){
        if(this.histogramIndex==0){
            this.histogramIndex ++
        }
    },
    async getYearActive(){
      const { data } = await AssetApi.statisicsYearActive({year:'2023'})
      this.dataList = data
      this.maxSubtotal = Math.max.apply(Math,data.map(item => { return item.subtotal }))
    }
  },
};
</script>

<style lang="less" scoped>
.active-num {
  padding: 10px;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .tip {
      color: #999;
      font-size: 12px;
      margin-left: 10px;
    }
    .year {
      border: 1px solid #999;
      width: 60px;
      height: 24px;
      border-radius: 6px;
      text-align: center;
      line-height: 24px;
      font-size: 12px;
    }
  }
  .histogram {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap:15px;
    // .arrow-btn{
    .arrow-back-btn {
      background: #f1f1f1;
      width: 32px;
      height: 32px;
      border-radius: 16px;
      // text-align: center;
      // line-height: 32px;
      font-weight: bold;
      display: flex;
      align-items: center;
      .arrow-back-cion {
        margin-left: 7px;
      }
    }
    // }
  }
  .histogram-content{
    width:220px;
  }
  .histogram-list {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    .histogram-item {
      height: 200px;
      display: flex; /* 设置弹性布局 */
      flex-direction: column; /* 将主轴设置为竖直方向 */
      align-items: center; /* 在交叉轴上居中 */
      justify-content: flex-end;
      >div{
        margin-top:5px;
        font-size: 12px;
      }

      .column {
        width: 20px;
        background: #c2dcfd;
        border-radius: 6px;
      }
    }
  }
}
</style>
